
package nb314calendargui;

import static org.junit.Assert.*;
import org.junit.Test;
import java.util.*;
import java.text.*;

/**
 * Tests that the GUI object is created
 * 
 * Test will initialize data and test that the
 * data was saved properly
 */
public class JUnitTest_Cal {

	@Test
	public void test_CalUI() {
		// testing variables below 
		testCalendarUI testUIObj = new testCalendarUI();
		String[] arrCalUI = new String[10];
		
	 /* // test strings
        String testTitle = "Test Title";
        String testLocation = "Test Location - Honolulu, Hawaii";
        String testResources = "Test Resourses - computer, mouse, study material";
        String testPriorityHigh = "1";
        String testClassification = "CONFIDENTIAL";
        String testDescription = "This is a test event, using java implementation.";
        
        String testDateStart    = "20120808";
        String testTimeStart    = "120000";
        String testDateEnd      = "20120808";
        String testTimeEnd      = "140000"; */

        // ******* test that CalUI object was created
        assertNotNull(testUIObj);
        
        // all values of the object should be null 
        for (int i = 0; i < arrCalUI.length; i++)
        {
        	arrCalUI[i] = null;
        }
        
        assertArrayEquals("PROBLEM - Arrays do NOT have equal values stored",
				arrCalUI, testUIObj.getAllValues());
        
        // test that input is correctly conformed to RFC
     /* assertEquals(testTitle, arrCalUI[0]);           // eventName
        assertEquals(testResources, arrCalUI[1]);       // resources
        assertEquals(testLocation, arrCalUI[2]);        // location
        assertEquals(testDescription, arrCalUI[3]);     // desc
        assertEquals(testPriorityHigh, arrCalUI[4]);    // priority
        assertEquals(testClassification, arrCalUI[5]);  // privacy
        assertEquals(testTimeStart, arrCalUI[6]);       // timeStart
        assertEquals(testTimeEnd, arrCalUI[7]);         // timeEnd
        assertEquals(testDateStart, arrCalUI[8]);       // dateStart
        assertEquals(testDateEnd, arrCalUI[9]);         // dateEnd */
	}
	
	/**
	 * Test will test that an iCalEvent is
	 * made and that the data being tested is
	 * saved as expected
	 */
	@Test
    public void test_iCalEvent() {
		testICalEvent testICalObj = new testICalEvent();
		String[] arrICalEvent = new String[15];
		
        // test Strings 
		String testContent = null;
		String testFileNameString = "test_Filename.ics";
        String testTitle          = "Test Title";
        String testLocation       = "Test Location - Honolulu, Hawaii";
        String testResources      = "Test Resourses - computer, mouse, study material";
        String testPriorityHigh   = "1";
        String testClassification = "CONFIDENTIAL";
        String testDescription    = "This is a test event, using java implementation.";
        
        String testDateStart    = "20120808";
        String testTimeStart    = "120000";
        String testDateEnd      = "20120808";
        String testTimeEnd      = "140000";
        
        // From iCalEvent
        String testDate_Start = testDateStart + "T" + testTimeStart + "\n";
        String testDate_End = testDateEnd + "T" + testTimeEnd +"\n";
        
        // ******* test that event object was created
        assertNotNull(testICalObj);
        
        // all values of the object should be null 
        for (int i = 0; i < arrICalEvent.length; i++)
        {
        	arrICalEvent[i] = null;
        }
        
        assertArrayEquals("PROBLEM - Arrays do NOT have equal values stored",
        				arrICalEvent, testICalObj.getAllValues());
        
        // set for debugging purposes
        String testDSTname = "Hawaii Daylight Time" + "\n";
        String testSTname = "Hawaii Standard Time" + "\n";
        
        // set for debugging
        String testUTCoffset = "-1000\n";
        String testSTime = "-1000\n";   
        
        // *** Code taken from method - boolean createFile() from iCalEvent.java
        testContent = 
                "BEGIN:VCALENDAR\n" +
                "VERSION:2.0\n" +
                "PRODID:-//ICS314 Congaree//Eventer 1.0//EN\n" +
                  
                /* Timezone component */
                "BEGIN:VTIMEZONE\n" +
                "TZID:" + "Pacific/Honolulu" + "\n" +
                "BEGIN:DAYLIGHT\n" +
                "COMMENT:Info for daylight savings\n" +
                "TZOFFSETFROM:" +  testUTCoffset +
                "DTSTART:" + "19330430T020000\n" +
                "TZNAME:" +  testDSTname +
                "TZOFFSETTO:" + testSTime +
                "RDATE:" + "19330430T020000\n" +
                "END:DAYLIGHT\n" +
                "BEGIN:STANDARD\n" +
                "COMMENT:Info for standard time\n" +
                "TZOFFSETFROM:" + testUTCoffset +
                "DTSTART:" + "19470608T020000\n" +
                "TZNAME:" + testSTname +
                "TZOFFSETTO:" + testSTime +
                "RDATE:" + "19470608T020000\n" +
                "END:STANDARD\n" +
                "END:VTIMEZONE\n" +
                  
                /* Event component */
                "BEGIN:VEVENT\n" +
                "COMMENT:Event details found below\n" +
                "CREATED:" + "20120808"+ "T" + "120000" + "Z\n" +
                "UID:" + "DefaultUser" + "\n" + // Add UID here
                "CLASS:" + testClassification + "\n" +
                "PRIORITY:" + testPriorityHigh + "\n" +
                "DTSTART;TZID=" + "Pacific/Honolulu" + ":" + testDate_Start +
                "DTEND;TZID=" + "Pacific/Honolulu" + ":" + testDate_End + 
                
                /* Event is marked as busy by default */
                /* User cannot change when creating .ics file */
                /* User can change from busy to free after importing */
                "TRANSP:OPAQUE\n" +
                "SUMMARY:" + testTitle + "\n" +
                "LOCATION:" + testLocation + "\n" +
                "RESOURCES:" + testResources + "\n" +
             // testTimeStamp + "\n" +
                "DESCRIPTION:" + testDescription  + "\n" +
                "END:VEVENT\n" +
                "END:VCALENDAR\n";
        // End of testContent creation from code from iCalEvent.java
        
        // re-assign object
        testICalObj = new testICalEvent(testTitle, testDateStart, testDateEnd, testTimeStart,
                testTimeEnd, testLocation, testResources, testClassification, testPriorityHigh,
                testDescription);
        
        // create file so as to set content variable
        testICalObj.createFile();
        
        // re-assign data array
        arrICalEvent = testICalObj.getAllValues();
        
        // test that input is correctly conformed to RFC
        assertEquals(testDSTname, arrICalEvent[0]);          // DSTname 
        assertEquals(testSTname, arrICalEvent[1]);           // STname 
        assertEquals(testUTCoffset, arrICalEvent[2]);        // UTCoffset
        assertEquals(testSTime, arrICalEvent[3]);            // sTime
        assertEquals(testDate_Start, arrICalEvent[4]);       // date_start
        assertEquals(testDate_End, arrICalEvent[5]);         // date_end
        assertEquals("CLASS:" + testClassification + "\n", arrICalEvent[6]);      // classification
        assertEquals("PRIORITY:" + testPriorityHigh + "\n", arrICalEvent[7]);     // priority
        assertEquals("LOCATION:" + testLocation + "\n", arrICalEvent[8]);         // location
        assertEquals("RESOURCES:" + testResources + "\n", arrICalEvent[9]);       // resources
        assertEquals("DESCRIPTION:" + testDescription + "\n", arrICalEvent[10]);  // description
        assertEquals("SUMMARY:" + testTitle + "\n", arrICalEvent[11]);            // title
     // assertEquals(testTimeStamp, arrICalEvent[12]);       // timestamp
        assertEquals(testFileNameString, arrICalEvent[13]);  // filename
        assertEquals(testContent, arrICalEvent[14]);         // content
	}

}
